package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Write;

public class WriteDAOImpl extends BaseHibernateDAOImpl<Write> implements WriteDAO {

	public Write getWriteByWriteID(String writeID) {
		Write write;
		try {
			write = (Write) getSession().get(Write.class, writeID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return write;
	}

	@SuppressWarnings("unchecked")
	public List<Write> getAllWrite() {
		List<Write> writes;
		try {
			Query query = getSession().getNamedQuery("AllWriteQuery");
			writes = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return writes;
	}

	@SuppressWarnings("unchecked")
	public List<Write> getAllWriteByPage(int currentPage, int lineSize) {
		List<Write> writes;
		try {
			Query query = getSession().getNamedQuery("AllWriteByPageQuery");
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			writes = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return writes;
	}

}
